package com.itsenpupulai.bdtest.listener;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.itsenpupulai.bdtest.bean.User;
import com.itsenpupulai.bdtest.utils.DBUtil;

import java.util.Date;

/**
 * Created by Administrator on 2017/5/11.
 */

public class MyLocationListener implements BDLocationListener {
    private User user = new User();

    @Override
    public void onReceiveLocation(BDLocation bdLocation) {
            setUser(bdLocation);
    }

    @Override
    public void onConnectHotSpotMessage(String s, int i) {

    }

    public void setUser(BDLocation location){
        if (location != null) {
            long time = new Date().getTime();
            user.setId(time);
            user.setAddress(location.getAddress() + "");
            user.setAddressStr(location.getAddrStr());
            user.setLongitude(String.valueOf((float) location.getLongitude()));
            user.setLatitude(String.valueOf((float) location.getLatitude()));
            user.setDate(location.getTime());
            if (location.getLocType() == 161) {
                user.setType("网络定位成功");
            }else if (location.getLocType() == 61){
                user.setType("GPS定位成功");
            }
            DBUtil.insertUser(user);
        }
    }
}
